#!/bin/bash

# Prints out the volume percentage

get_volume(){
	local VOLUME_ON_ICON=' '
	local VOLUME_MUTED_ICON=' '

        local active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}')
        local curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}')
        local volume=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ')

        if [ "${curStatus}" = 'yes' ]
        then
            #echo "$VOLUME_MUTED_ICON$volume%"
	    printf "$VOLUME_MUTED_ICON$volume"
        else
            #echo "$VOLUME_ON_ICON$volume%"
	    printf "$VOLUME_ON_ICON$volume"
        fi
}

get_volume
